// --------------------------------------------------------------------------------------------------------------------
// <copyright file="KinectProcessorTest.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Test.Robotics.Runtime
{
    using System;
    using System.Drawing;
    using System.Reflection;
    using System.Runtime.Serialization;
    using System.Threading;
    using Microsoft.Robotics.Numerics;
    using Microsoft.Robotics.Runtime;
    using Microsoft.Robotics.Vision;
    using Microsoft.Robotics.Vision.Cameras;
    using Microsoft.Robotics.Vision.Runtime.Cameras;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Test.Robotics.Runtime;

    /// <summary>
    /// Validates that message synchronization works as expected.
    /// </summary>
    [TestClass]
    [DeploymentItem("Microsoft.Robotics.Vision.Interop.dll")]
    public class RGBCameraAgentTest
    {
        /// <summary>
        /// Send the RGBCamera Agent a timer message and ensure you get a valid frame back.
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void RGBCameraPipelineTest()
        {

            Manifest manifest = new Manifest();

            // add the agents 
            RGBCameraAgent rgbCameraAgent = new RGBCameraAgent(
                name: "RGBCamera",
                width: 640,
                height: 480,
                frameRate: 15,
                subType: "YUY2",
                friendlyName: "");

            manifest.Agents.Add(rgbCameraAgent);

            MessageCollectorAgent<RGBCameraAgentMessage> collector = 
                new MessageCollectorAgent<RGBCameraAgentMessage>("collector", rgbCameraAgent);
            manifest.Agents.Add(collector);

            manifest.ActiveAgents.Add(rgbCameraAgent.Name);
            manifest.ActiveAgents.Add(collector.Name);

            AgentLocator locator = new AgentLocator();
            locator.LoadFrom(manifest);

            // Wait for the message to appear at end of pipeline
            collector.Wait(30000);

            locator.Deactivate();
            
            Assert.IsTrue(
                collector.Results.Count >= 1,
                string.Format("Expected 1 or more message at end of pipeline found {0}", collector.Results.Count));
        }

    }
}
